package com.powernode.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.HotSearch;
import com.powernode.domain.IndexImg;
import com.powernode.service.HotSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/hotSearch")
@Api(tags = "热搜")
public class HotSearchController {
    @Autowired
    private HotSearchService hotSearchService;


    @GetMapping("/page")
    @ApiOperation(value = "热搜管理分页")
    @PreAuthorize("hasAuthority('admin:hotSearch:page')")
    public ResponseEntity<Page<HotSearch>> hotSearchPage(Page<HotSearch> page, HotSearch hotSearch) {
        page = hotSearchService.hotSearchPage(page, hotSearch);
        return ResponseEntity.ok(page);
    }


    @PostMapping
    @ApiOperation(value = "热搜新增")
    @PreAuthorize("hasAuthority('admin:hotSearch:save')")
    public ResponseEntity<Void> addIndexImg(@RequestBody HotSearch hotSearch) {
        hotSearchService.save(hotSearch);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/hotSearchByShopId")
    @ApiOperation(value = "小程序热搜")
    public ResponseEntity<List<HotSearch>> hotSearchByShopId(Integer number) {
        List<HotSearch> list=  hotSearchService.hotSearchByShopId(number);
        return ResponseEntity.ok(list);
    }
}
